#!/usr/bin/python3
# -*- coding:utf-8 -*-
# __author__ == taoyulong2018@gmail.com
# __time__ == 2023/8/16 16:41
# ===========================================
#       题目名称： 1. 两数之和
#       题目地址： https://leetcode.cn/problems/two-sum/
#       题目描述： https://note.youdao.com/s/RRXNSXjR
# # ===========================================


class Solution:
    """
        实现逻辑：
            通过定义一个字典， k 存差  v 存被减的值 然后再遍历字典就可得到
    """
    def twoSum(self, nums, target):
        """
            @param nums {list} 数值
            @param target {int} 目标值
            @result pointer {list} 返回坐标值
        """
        pointer = []
        difference_dict = dict()
        for i in range(len(nums)):
            difference = target - nums[i]
            difference_dict[difference] = i
        for k, v in difference_dict.items():
            if k in nums and nums.index(k) != v:
                pointer = [nums.index(k), v]
                break
        return pointer


if __name__ == '__main__':
    s = Solution()
    print("[0,1] =>", s.twoSum(nums=[2, 7, 11, 15], target=9))
    print("[1,2] =>", s.twoSum(nums=[3, 2, 4], target=6))
    print("[0,1] =>", s.twoSum(nums=[3, 3], target=6))
